import Taro, { useState, useDidShow, useEffect } from '@tarojs/taro'
import { AtCard, AtList, AtListItem, AtButton } from 'taro-ui'
import servicePath from '../../config/apiUrl'
import { View, Text } from '@tarojs/components'
import "../goods/goodScss.scss"
import 'taro-ui/dist/style/components/flex.scss'
import { axios } from 'taro-axios'



function GoodInfo(props) {

    const [userId, setUserId] = useState(0)

    const [goodInfo, setGoodInfo] = useState([])


    useEffect(() => {
        setTimeout(() => {
            setUserId(this.$router.params.id)
        }, 50)
        console.log('id=' + userId)

        axios({
            method: 'post',
            url: servicePath.getGoodInfo,
            data: {
                'userId': userId
            },
            withCredentials: true
        }).then(
            res => {
                console.log(res.data)

                setGoodInfo(res.data.data)


            })

    }, [userId])

    const testHandle = () => {
        console.log(goodInfo);

    }

    return (
        <View>
            {
                goodInfo.map((item, index) => {
                    return (
                        <View key={index + item}>

                            <AtCard
                                className='my-card'
                                title={item.name}
                            ><Image
                                    className='my-img'
                                    src={item.img}
                                />
                            </AtCard>
                            <View className='my-view'>
                                <View >{item.info}</View>
                                <View >{item.price}</View>
                            </View>
                            <AtButton type='primary' onClick={testHandle}>加入购物车</AtButton>
                        </View>
                    )
                })
            }
        </View>
    )

}

export default GoodInfo 